﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;

namespace Server_NhaSach.DataAccess.LogicLayer
{
    [Serializable]
    public class TaiKhoanOnlineDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertTKOL(TaiKhoanOnlineDTO TaiKhoanOnline)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[7];
            par[0] = new SqlParameter("@MATKOL", TaiKhoanOnline.MaTKOL);
            par[1] = new SqlParameter("@TenDangNhap", TaiKhoanOnline.Tendangnhap);
            par[2] = new SqlParameter("@MatKhau", TaiKhoanOnline.Matkhau);
            par[3] = new SqlParameter("@DiaChi", TaiKhoanOnline.Diachi);
            par[4] = new SqlParameter("@SDT", TaiKhoanOnline.Dienthoai);
            par[5] = new SqlParameter("@Email", TaiKhoanOnline.Email);
            par[6] = new SqlParameter("@NgayDangKy", TaiKhoanOnline.Ngaydangky);
            try
            {
                helper.InsertQuery("sp_Insert_TaiKhoanOnline", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateTKOL(TaiKhoanOnlineDTO TaiKhoanOnline)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[7];
            par[0] = new SqlParameter("@MATKOL", TaiKhoanOnline.MaTKOL);
            par[1] = new SqlParameter("@TenDangNhap", TaiKhoanOnline.Tendangnhap);
            par[2] = new SqlParameter("@MatKhau", TaiKhoanOnline.Matkhau);
            par[3] = new SqlParameter("@DiaChi", TaiKhoanOnline.Diachi);
            par[4] = new SqlParameter("@SDT", TaiKhoanOnline.Dienthoai);
            par[5] = new SqlParameter("@Email", TaiKhoanOnline.Email);
            par[6] = new SqlParameter("@NgayDangKy", TaiKhoanOnline.Ngaydangky);
            try
            {
                helper.UpdateQuery("sp_Update_TaiKhoanOnline", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteTKOL(string maTKOL)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maTKOL", maTKOL);
            try
            {
                helper.DeleteQuery("sp_Delete_TaiKhoanOnline", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_TaiKhoanOnline()
        {
            helper = new Helper();
            DataSet ds_tkol = helper.SelectQuery("sp_LayDS_TaiKhoanOnline");
            return ds_tkol;
        }
        #endregion
    }
}